const prompts = require('prompts')
const { exec } = require('child_process')
const process = require('node:process')
const onCancel = () => {
  console.log('退出代理')
  process.exit()
}
;(async () => {
  const response = await prompts(
    {
      type: 'text',
      name: 'username',
      message: 'username'
    },
    { onCancel }
  )
  const username = response.username
  if (!username) return
  const shell = `ssh -D 1091 -L 8081:192.168.200.23:80 -N ${username}`
  exec(shell, (error, stdout, stderr) => {
    console.log(error, stdout, stderr)
    if (!error) {
      // 成功
    } else {
      // 失败
    }
  })
})()
